#include <stdio.h>
#include <stdlib.h>

typedef struct node 
{
	int data;
	void *next;
} node_t;

int revert(node_t **val)
{
	node_t *pre=NULL, *cur=NULL, *next=NULL;
	cur = *val;
	
	while((next = cur->next))
	{
		cur->next = pre;
		pre = cur;
		cur = next;
	}
	cur->next = pre;
	*val = cur;

	return 0;
}

int init_node(node_t **ret, int num)
{
	int size = 0;
	int i=0;
	node_t *tmp, *cur;

	size = sizeof(node_t);
	*ret = malloc(size);

	if(*ret)
	{
		cur = *ret;
		for(i=0;i<num;i++)
		{
			tmp = malloc(size);
			tmp->data = i+1;
			tmp->next = NULL;

			cur->next = tmp;
			cur = tmp;
		}
	}

	return 0;
}

#define INIT_NODE(ret, num) init_node(ret, num);

int each_node(node_t *node)
{
	node_t *val;

	val = node;
#ifdef DOWHILE
	do {
		printf("%p=%d,", val, (int)val->data);
		val=val->next;
	} while(val); //必须写分号
#else
	while(val)
	{
		printf("%p=%d,", val, (int)val->data);
		val=val->next;
	}
#endif

	printf("\n");

	return 0;
}

int main()
{
	node_t *node;

	INIT_NODE(&node, 10);

	each_node(node);

	revert(&node);

	each_node(node);

	return 0;
}

